package cn.wolfcode.mongo.service.impl;

import cn.wolfcode.mongo.domain.User;
import cn.wolfcode.mongo.repository.UserRepository;
import cn.wolfcode.mongo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserRepository repository;


    @Override
    public void save(User user) {
        repository.save(user);
    }

    @Override
    public void update(User user) {
        repository.save(user);
    }

    @Override
    public void delete(String id) {
          repository.deleteById(id);
    }

    @Override
    public User get(String id) {
        return repository.findById(id).get();
    }

    @Override
    public List<User> list() {
        return repository.findAll();
    }

    @Override
    public User findByName(String name) {
        return repository.findByName(name);
    }

    @Override
    public User findByNameAndAge(String name,Integer age) {
        return repository.findByNameAndAge(name,age);
    }

    @Override
    public List<User> findByNameOrAge(String name, Integer age) {
        return repository.findByNameOrAge(name,age);
    }

    @Override
    public List<User> findByAgeBetween(Integer min,Integer max) {
        return repository.findByAgeBetween(min,max);
    }

    @Override
    public List<User> findByAgeLessThan(Integer age) {
        return repository.findByAgeLessThan(age);
    }

    @Override
    public List<User> findByAgeLessThanEqual(Integer age) {
        return repository.findByAgeLessThanEqual(age);
    }

    @Override
    public List<User> findByAgeGreaterThan(Integer age) {
        return repository.findByAgeGreaterThan(age);
    }

    @Override
    public List<User> findByAgeGreaterThanEqual(Integer age) {
        return repository.findByAgeGreaterThanEqual(age);
    }

    @Override
    public List<User> findByNameIsNull() {
        return repository.findByNameIsNull();
    }

    @Override
    public List<User> findByNameIsNotNull() {
        return repository.findByNameIsNotNull();
    }

    @Override
    public List<User> findByNameLike(String name) {
        return repository.findByNameLike(name);
    }

    @Override
    public List<User> findByNameNotLike(String name) {
        return repository.findByNameNotLike(name);
    }

    @Override
    public List<User> findByNameStartingWith(String name) {
        return repository.findByNameStartingWith(name);
    }

    @Override
    public List<User> findByNameEndingWith(String name) {
        return repository.findByNameEndingWith(name);
    }

    @Override
    public List<User> findByNameContaining(String name) {
        return repository.findByNameContaining(name);
    }

    @Override
    public List<User> findByNameNot(String name) {
        return repository.findByNameNot(name);
    }

    @Override
    public List<User> findByNameIn(List<String> names) {
        return repository.findByNameIn(names);
    }

    @Override
    public List<User> findByNameNotIn(List<String> names) {
        return repository.findByNameNotIn(names);
    }

    @Override
    public List<User> findByNameIgnoreCase(String name) {
        return repository.findByNameIgnoreCase(name);
    }
}
